﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using PS.DBUtility;
namespace PS.DAL
{
    /// <summary>
    /// 数据访问类:RepProjectPicture
    /// </summary>
    public partial class RepProjectPicture
    {
        public RepProjectPicture()
        { }
        #region  Method
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int PictureID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from RepProjectPicture");
            strSql.Append(" where PictureID=@PictureID");
            SqlParameter[] parameters = {
					new SqlParameter("@PictureID", SqlDbType.Int,4)
};
            parameters[0].Value = PictureID;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(PS.Model.RepProjectPicture model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into RepProjectPicture(");
            strSql.Append("RepProjectInfoID,ImageName,ImageDescription,ImageFile,Creator,CreateTime,DispOrder,ImageType,Spare1,Spare2,Spare3,Spare4)");
            strSql.Append(" values (");
            strSql.Append("@RepProjectInfoID,@ImageName,@ImageDescription,@ImageFile,@Creator,@CreateTime,@DispOrder,@ImageType,@Spare1,@Spare2,@Spare3,@Spare4)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
					new SqlParameter("@RepProjectInfoID", SqlDbType.Int,4),
					new SqlParameter("@ImageName", SqlDbType.VarChar,200),
					new SqlParameter("@ImageDescription", SqlDbType.VarChar,500),
					new SqlParameter("@ImageFile", SqlDbType.VarChar,100),
					new SqlParameter("@Creator", SqlDbType.VarChar,20),
					new SqlParameter("@CreateTime", SqlDbType.DateTime),
					new SqlParameter("@DispOrder", SqlDbType.Int,4),
					new SqlParameter("@ImageType", SqlDbType.Int,4),
					new SqlParameter("@Spare1", SqlDbType.VarChar,200),
					new SqlParameter("@Spare2", SqlDbType.VarChar,200),
					new SqlParameter("@Spare3", SqlDbType.VarChar,200),
					new SqlParameter("@Spare4", SqlDbType.VarChar,200)};
            parameters[0].Value = model.RepProjectInfoID;
            parameters[1].Value = model.ImageName;
            parameters[2].Value = model.ImageDescription;
            parameters[3].Value = model.ImageFile;
            parameters[4].Value = model.Creator;
            parameters[5].Value = model.CreateTime;
            parameters[6].Value = model.DispOrder;
            parameters[7].Value = model.ImageType;
            parameters[8].Value = model.Spare1;
            parameters[9].Value = model.Spare2;
            parameters[10].Value = model.Spare3;
            parameters[11].Value = model.Spare4;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(PS.Model.RepProjectPicture model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update RepProjectPicture set ");
            strSql.Append("RepProjectInfoID=@RepProjectInfoID,");
            strSql.Append("ImageName=@ImageName,");
            strSql.Append("ImageDescription=@ImageDescription,");
            strSql.Append("ImageFile=@ImageFile,");
            strSql.Append("Creator=@Creator,");
            strSql.Append("CreateTime=@CreateTime,");
            strSql.Append("DispOrder=@DispOrder,");
            strSql.Append("ImageType=@ImageType,");
            strSql.Append("Spare1=@Spare1,");
            strSql.Append("Spare2=@Spare2,");
            strSql.Append("Spare3=@Spare3,");
            strSql.Append("Spare4=@Spare4");
            strSql.Append(" where PictureID=@PictureID");
            SqlParameter[] parameters = {
					new SqlParameter("@RepProjectInfoID", SqlDbType.Int,4),
					new SqlParameter("@ImageName", SqlDbType.VarChar,200),
					new SqlParameter("@ImageDescription", SqlDbType.VarChar,500),
					new SqlParameter("@ImageFile", SqlDbType.VarChar,100),
					new SqlParameter("@Creator", SqlDbType.VarChar,20),
					new SqlParameter("@CreateTime", SqlDbType.DateTime),
					new SqlParameter("@DispOrder", SqlDbType.Int,4),
					new SqlParameter("@ImageType", SqlDbType.Int,4),
					new SqlParameter("@Spare1", SqlDbType.VarChar,200),
					new SqlParameter("@Spare2", SqlDbType.VarChar,200),
					new SqlParameter("@Spare3", SqlDbType.VarChar,200),
					new SqlParameter("@Spare4", SqlDbType.VarChar,200),
					new SqlParameter("@PictureID", SqlDbType.Int,4)};
            parameters[0].Value = model.RepProjectInfoID;
            parameters[1].Value = model.ImageName;
            parameters[2].Value = model.ImageDescription;
            parameters[3].Value = model.ImageFile;
            parameters[4].Value = model.Creator;
            parameters[5].Value = model.CreateTime;
            parameters[6].Value = model.DispOrder;
            parameters[7].Value = model.ImageType;
            parameters[8].Value = model.Spare1;
            parameters[9].Value = model.Spare2;
            parameters[10].Value = model.Spare3;
            parameters[11].Value = model.Spare4;
            parameters[12].Value = model.PictureID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int PictureID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from RepProjectPicture ");
            strSql.Append(" where PictureID=@PictureID");
            SqlParameter[] parameters = {
					new SqlParameter("@PictureID", SqlDbType.Int,4)
};
            parameters[0].Value = PictureID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string PictureIDlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from RepProjectPicture ");
            strSql.Append(" where PictureID in (" + PictureIDlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public PS.Model.RepProjectPicture GetModel(int PictureID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 PictureID,RepProjectInfoID,ImageName,ImageDescription,ImageFile,Creator,CreateTime,DispOrder,ImageType,Spare1,Spare2,Spare3,Spare4 from RepProjectPicture ");
            strSql.Append(" where PictureID=@PictureID");
            SqlParameter[] parameters = {
					new SqlParameter("@PictureID", SqlDbType.Int,4)
};
            parameters[0].Value = PictureID;

            PS.Model.RepProjectPicture model = new PS.Model.RepProjectPicture();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["PictureID"].ToString() != "")
                {
                    model.PictureID = int.Parse(ds.Tables[0].Rows[0]["PictureID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["RepProjectInfoID"].ToString() != "")
                {
                    model.RepProjectInfoID = int.Parse(ds.Tables[0].Rows[0]["RepProjectInfoID"].ToString());
                }
                model.ImageName = ds.Tables[0].Rows[0]["ImageName"].ToString();
                model.ImageDescription = ds.Tables[0].Rows[0]["ImageDescription"].ToString();
                model.ImageFile = ds.Tables[0].Rows[0]["ImageFile"].ToString();
                model.Creator = ds.Tables[0].Rows[0]["Creator"].ToString();
                if (ds.Tables[0].Rows[0]["CreateTime"].ToString() != "")
                {
                    model.CreateTime = DateTime.Parse(ds.Tables[0].Rows[0]["CreateTime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["DispOrder"].ToString() != "")
                {
                    model.DispOrder = int.Parse(ds.Tables[0].Rows[0]["DispOrder"].ToString());
                }
                if (ds.Tables[0].Rows[0]["ImageType"].ToString() != "")
                {
                    model.ImageType = int.Parse(ds.Tables[0].Rows[0]["ImageType"].ToString());
                }
                model.Spare1 = ds.Tables[0].Rows[0]["Spare1"].ToString();
                model.Spare2 = ds.Tables[0].Rows[0]["Spare2"].ToString();
                model.Spare3 = ds.Tables[0].Rows[0]["Spare3"].ToString();
                model.Spare4 = ds.Tables[0].Rows[0]["Spare4"].ToString();
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select PictureID,RepProjectInfoID,ImageName,ImageDescription,ImageFile,Creator,CreateTime,DispOrder,ImageType,Spare1,Spare2,Spare3,Spare4 ");
            strSql.Append(" FROM RepProjectPicture ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" PictureID,RepProjectInfoID,ImageName,ImageDescription,ImageFile,Creator,CreateTime,DispOrder,ImageType,Spare1,Spare2,Spare3,Spare4 ");
            strSql.Append(" FROM RepProjectPicture ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "RepProjectPicture";
            parameters[1].Value = "PictureID";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  Method
    }
}

